package com.mvprxjavartrofit.ui.login;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.mvprxjavartrofit.R;
import com.mvprxjavartrofit.base.BaseActivity;
import com.mvprxjavartrofit.ui.home.HomeActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class LoginActivity extends BaseActivity<LoginPresenter, LoginModel> implements LoginContract.View {
    private ProgressDialog pd;

    @BindView(R.id.btn_login)
    Button btnLogin;
    @BindView(R.id.activity_login)
    RelativeLayout activityLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    public void initView() {
        unbinder = ButterKnife.bind(this);
    }

    @OnClick({R.id.btn_login, R.id.activity_login})
    public void onClick(View view) {
        switch(view.getId()) {
            case R.id.btn_login:
                showProgress();
                presenter.login();
                break;
            case R.id.activity_login:
                break;
        }
    }

    @Override
    public void showProgress() {
        if(pd == null){
            pd = new ProgressDialog(this);
        }
        pd.setCancelable(false);
        if(!pd.isShowing()){
            pd.show();
        }
    }

    @Override
    public void showMessage(String message) {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
        dismissProgress();
    }

    @Override
    public void dismissProgress() {
        if(pd != null && pd.isShowing()){
            pd.dismiss();
        }
    }

    @Override
    public void showSucc() {
        Toast.makeText(this, "login succ", Toast.LENGTH_SHORT).show();
        dismissProgress();
        startActivity(new Intent(this, HomeActivity.class));
    }


}
